package com.xiaoma.verbal.web.front;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaoma.verbal.dto.TpoVo;
import com.xiaoma.verbal.service.ForecastService;
import com.xiaoma.verbal.service.QuClassicService;
import com.xiaoma.verbal.service.QuTpoService;
import com.xiaoma.verbal.service.QuestionService;
import com.xiaoma.verbal.utils.HandleResultUtils;
import com.xiaoma.verbal.utils.MemoryDB;
import com.xiaoma.verbal.webservice.VerbalQuestionWS;

import static com.xiaoma.verbal.utils.Constants.FTC;
import static com.xiaoma.verbal.utils.Constants.QCTC;
import static com.xiaoma.verbal.utils.Constants.QTTC;

@Controller
@RequestMapping("/cache")
public class CacheAct {
	@Autowired
	private ForecastService forecastService;
	@Autowired
	private QuestionService questionService;
	@Autowired
	private QuClassicService quClassicService;
	@Autowired
	private QuTpoService quTpoService;
	private static Logger LOG = LoggerFactory.getLogger(VerbalQuestionWS.class);
	@RequestMapping(value = "/reload", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> tops() {
		Map<String, Object> result = new HashMap<String, Object>();

		try {
			Long ftc = forecastService.getTimeCoordinate();
			Long qctc = quClassicService.getTimeCoordinate();
			Long qttc = quTpoService.getTimeCoordinate();
			MemoryDB.put(FTC, ftc);
			MemoryDB.put(QCTC, qctc);
			MemoryDB.put(QTTC, qttc);
			result.put("ftc", ftc);
			result.put("qctc", qctc);
			result.put("qttc", qttc);
			HandleResultUtils.success(result);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace(); 
			HandleResultUtils.failure(result);
		}

		return result;
	}

}
